#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define POS_FILENAME	"/sys/devices/platform/hdaps/position"

struct pos_t {
	int f1;
	int f2;
};

int main(int argc, char **argv)
{
	struct pos_t pos;
	FILE *pos_fp;
	double poll_freq;
	char s[128];
	char *endptr;
	char input[32];

	if (argc != 2) {
		fprintf(stderr, "%s: usage: %s <poll_frequency_ms>\n", argv[0], argv[0]);
		return 1;
	}

	pos_fp = fopen(POS_FILENAME, "r");
	if (!pos_fp) {
		fprintf(stderr, "%s: failed to open " POS_FILENAME " for reading\n", argv[0]);
		return 1 << 1;
	}

	while (1) {
		fgets(s, sizeof s, pos_fp);
		pos.f1 = (int) strtol(&s[1], &endptr);
		pos.f2 = (int) strtol(endptr + 1, NULL);

		printf("[%d, %d],\n", pos.f1, pos.f2);

		usleep((unsigned int) poll_freq * 10000);
		;
	}

	return 0;
}
